#include"tools/Types.h"
#include"tools/DataLoder.h"
#include <iostream>
#include <string>
// #include <pangolin/pangolin.h>
// #include "Sample.h"
#include "NRreger.h"
#include "DEM.h"
#include "tools/OmpHelper.h"


Paras paras;
int main()
{
    //1.能量大于某一个阈值需要

    /*step1:设定参数*/
    //数据
    paras.datapath = "/home/mx/桌面";    //图片路径
    paras.n_strat_ = 301;               //从第301张图片开始重建
    paras.max_picture_num = 108;        //最大图片数量

    paras.keyframe_inte = 7;

    //优化参数
    paras.max_iters = 20;
    paras.alpha = 1;
    paras.beta = 0.1;
    paras.tps = 0.1;

    //能量函数构造
    paras.searchratio = 1.1;              //影响了F、W、M矩阵的构造
    paras.Tps_R = 1.1;
    paras.flow_filter = 500;//每1000个匹配点筛选一个
    paras.DEM_resolusion = 0.5;
    paras.TPS_resolusion = 2;

    DataLoder* dataloder = new DataLoder(paras);

    Timer time;
    NRreger* reg = new NRreger(dataloder,paras);
    for(int i =0;i<paras.max_picture_num;i++)
    {
        if(i%paras.keyframe_inte==0)
        {
            reg->Initial_GPU(i);
            reg->DoNonRigid();
            auto pc = reg->Shower_GPU();
            std::shared_ptr<open3d::geometry::PointCloud> ptrpc (new open3d::geometry::PointCloud); 
            *ptrpc = pc;
            open3d::visualization::DrawGeometries({ptrpc},"PC",640,480,50,50);
        }

    //     // auto mesh = reg->Shower();
    //     // std::shared_ptr<open3d::geometry::TriangleMesh> ptrmesh (new open3d::geometry::TriangleMesh);
    //     // *ptrmesh = mesh;
    //     // open3d::visualization::DrawGeometries({ptrmesh},"Mesh",640,480,50,50,true,false,true);
    // }
    }

    










    /*
    auto pc = dataloder->PcRecover(30);
    DEM* dem;
    dem = new DEM();
    dem->DEM_generate(pc,1);
    dem->ExtractWarppc(3);
    
    // auto pcwarp = dem->Getwarppc();
    // std::cout<<pcwarp.points_.size()<<std::endl;
    // std::shared_ptr<open3d::geometry::PointCloud> ptrpc (new open3d::geometry::PointCloud);
    // *ptrpc = pcwarp;
    // open3d::visualization::DrawGeometries({ptrpc},"PC",640,480,50,50);
    




    PointCloud dempc = dem->Generate_pc();
    std::shared_ptr<open3d::geometry::PointCloud> ptrpc (new open3d::geometry::PointCloud);
    *ptrpc = dempc;
    open3d::visualization::DrawGeometries({ptrpc},"PC",640,480,50,50);

    open3d::geometry::TriangleMesh mesh = dem->Generate_mesh();
    // mesh.ComputeVertexNormals();
    mesh.ComputeTriangleNormals();
    std::shared_ptr<open3d::geometry::TriangleMesh> ptrmesh (new open3d::geometry::TriangleMesh);
    *ptrmesh = mesh;
    open3d::visualization::DrawGeometries({ptrmesh},"Mesh",640,480,50,50,true,false,true);
    */










    return 0;
}